<?php

namespace App\Http\Controllers\Front;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\ApiController;
use App\Models\Banner;
use App\Models\Product;
use App\Models\Article;

class HomeController extends ApiController
{
    /**
     * 首页
     */
    public function index(Request $request)
    {
        return view('frontdev.home');
    }

    /**
     * 全国行情
     */
    public function market(Request $request)
    {
        $article = Article::where('alias', 'qghq')->first();
        return view('front.market.index', compact('article'));
    }

    /**
     * 获取首页数据(初始化数据)
     */
    public function fetchIndex()
    {
        $banner = Banner::orderBy('sort','DESC')->take(3)->get();
        return $this->success($banner);
    }


    /**
     * 首页推荐
     */
    public function recommend()
    {
        $reProduct = Product::published()
            ->orderBy('id','DESC')
            ->take(4)
            ->where('rcmd', 1)
            ->select('id', 'name', 'cover_image', 'price', 'views_num', 'self_support')
            ->get();

        return $this->success($reProduct);
    }
}
